﻿import arkadium.EncryptionManager;
import arkadium.TXTConfigFile
import arkadium.XMLConfigFile

class arkadium.AppConfigFile
{
	
	public var _cConfigFile_xml:XMLConfigFile;
	public var _cConfigFile_txt:TXTConfigFile;
	public var _oConfigFile_flv:Object;
	
	private var _cMainRoot;
	private var _sConfigFileType:String
	
	public function AppConfigFile(cMainRoot)
	{
		_cMainRoot = cMainRoot
		
	}
	
	public function setConfigDataFlv( pConfigDataObject ){
		_sConfigFileType = "flv";
		_oConfigFile_flv = pConfigDataObject;
		testAndHandleDecryption(_oConfigFile_flv);
		
	}
	
	public function loadConfigFile( oCallerObject:Object, fCallerFunction:Function, sFileURL:String ){
		/**************************************************************************************************\
		This function figures out if the file that is being loaded is xml or txt and captures the variables
		Also tracking whether it is txt or xml for the future when the code needs to get the data
		\**************************************************************************************************/
		
			
		
		_sConfigFileType = (sFileURL.slice((sFileURL.length-3),sFileURL.length));
		if(_sConfigFileType == "xml"){
			_cConfigFile_xml = new XMLConfigFile();
			_cConfigFile_xml.loadConfigFile( oCallerObject, fCallerFunction, sFileURL)
		}
		else if (_sConfigFileType == "txt"){
			_cConfigFile_txt = new TXTConfigFile();
			_cConfigFile_txt.loadConfigFile( oCallerObject, fCallerFunction, sFileURL)
		}
	}
	
	public function testAndHandleDecryption(){
		if(getData('params') != undefined){
			if(_sConfigFileType == "flv"){
				_cMainRoot._cEncryptionManager.decryptParams(_oConfigFile_flv,getData('params'));
			}
			else if(_sConfigFileType == "xml"){
				_cMainRoot._cEncryptionManager.decryptParams(_cConfigFile_xml,getData('params'));
			}
			else if(_sConfigFileType == "txt"){
				_cMainRoot._cEncryptionManager.decryptParams(_cConfigFile_txt,getData('params'));
			}
		}
	}
	
	public function getData( sVariableName:String ):String {
		if(_sConfigFileType == "flv"){
		  return(_oConfigFile_flv[sVariableName]);
		}
		else if(_sConfigFileType == "xml"){
			return(_cConfigFile_xml.getData( sVariableName ));
		}
		else if(_sConfigFileType == "txt"){
			return(_cConfigFile_txt.getData( sVariableName ));
		}
		
	}
	
	public function setData( varName_str:String, varValue){
		if(_sConfigFileType == "flv"){
			_oConfigFile_flv[varName_str] = varValue;
		}
		else if(_sConfigFileType == "xml"){
			_cConfigFile_xml.setData (varName_str, varValue);
		}
		else if(_sConfigFileType == "txt"){
			_cConfigFile_txt.setData (varName_str, varValue);
		}
	}

	
}